﻿#region

using System;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Minion.Win.Client.Notification;

#endregion

namespace Minion.Win.Client.Views
{
    public partial class NotificationComposer : PhoneApplicationPage
    {
        private Guid _pageId;

        public NotificationComposer()
        {
            InitializeComponent();
        }

        private void SendButton_Click(object sender, RoutedEventArgs e)
        {
            var message = Message.Text;
            var email = new Email(_pageId, message);
            if(email.SendNotification())
                NavigationService.GoBack();
            else
            {
                MessageBox.Show("Failed to send email. Try again later.", "Error", MessageBoxButton.OK);
            }
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var itemId = NavigationContext.QueryString["id"];
            if (string.IsNullOrEmpty(itemId)) _pageId = new Guid();
            else _pageId = new Guid(itemId);
        }
    }
}